package com.realworld.service.Impl;

import com.realworld.common.R;
import com.realworld.mapper.CommentsMapper;
import com.realworld.model.pojo.Comments;
import com.realworld.service.commentsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class commentsImpl implements commentsService {

    @Resource
    private CommentsMapper commentsMapper;
    @Override
    public R addComments(Comments comments) throws ParseException {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        Date parse = simpleDateFormat.parse(simpleDateFormat.format(date));
        comments.setCreateTime(parse);
        commentsMapper.addComments(comments);
        return R.ok(4001,"add success!");
    }

    @Override
    public List<Comments> getCommentsList(Integer artId) {
        List<Comments> commentsList = commentsMapper.getCommentsList(artId);
        return commentsList;
    }

    @Override
    public R deleteComments(Integer artId, String uid) {
        commentsMapper.deleteComments(artId,uid);
        return R.ok(4001,"delete success!");
    }
}
